<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/10/29
 * Time: 10:38
 */

namespace app\adminapiv3\controller;

//数据备份
class ServerDatabaseBak extends Base
{

    /**
     * @name 数据库地址设置
     * @author wx
     * @date 2019/11/29 13:19
     */
    public function list()
    {
        $params['type'] = $this->filterInput('type','get');
        $params['ctime'] = $this->filterInput('ctime','get');

        $server = new \app\adminapiv3\service\ServerDatabaseBak();
        $list = $server->toDo('list', [$params, $this->getLimit()]);

        $this->jsonOutPut($list);
    }

    /**
     * @name 备份
     * @author wx
     * @date 2020/4/22 10:24
     */
    public function backup()
    {
        global $logContent;
        $logContent = '备份数据库';

        $server = new \app\adminapiv3\service\ServerDatabaseBak();
        $server->backup();

        $this->jsonOutPut();
    }

    /**
     * @name 还原
     * @author wx
     * @date 2020/4/22 10:27
     */
    public function reset()
    {
        global $logContent;
        $logContent = '还原数据库';

        $id = $this->filterInput('id*', 'post');
        $server = new \app\adminapiv3\service\ServerDatabaseBak();
        $server->reset($id);

        //重启服务
        $rebootFilePath = $_SERVER['DOCUMENT_ROOT'].'/config/server_reboot.conf';
        file_put_contents($rebootFilePath, 'reboot server');

        $this->jsonOutPut();
    }

    /**
     * @name 清空备份目录
     * @author wx
     * @date 2020/4/22 10:32
     */
    public function clearDir()
    {
        global $logContent;
        $logContent = '清空备份目录';

        $server = new \app\adminapiv3\service\ServerDatabaseBak();
        $server->toDo('clearDir', []);

        $this->jsonOutPut();
    }

    /**
     * @name 清空数据库
     * @author wx
     * @date 2020/4/22 10:41
     */
    public function clear()
    {
        global $logContent;
        $logContent = '清空数据库';

        $server = new \app\adminapiv3\service\ServerDatabaseBak();
        $server->toDo('clear', []);

        $this->jsonOutPut();
    }




}